package cn.edu.neusoft.wuguangsheng.market.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.market.activity.FoodByShopActivity;
import cn.edu.neusoft.wuguangsheng.market.bean.MarketBean;

/**
 * Created by little on 2018/4/8.
 */

public class AllMarketAdapter extends BaseAdapter<MarketBean> {

    public AllMarketAdapter(Context context, List<MarketBean> items, int layoutResource) {
        super(context, items, layoutResource);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(context)
                .inflate(layoutResourse, parent, false);
        AllMarketViewHolder newCartCardViewHolder = new AllMarketViewHolder(itemView);
        return newCartCardViewHolder;
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        AllMarketViewHolder myViewHolder=(AllMarketViewHolder)holder;
        MarketBean marketBean=items.get(position);
        final String mrname=marketBean.getMrname();

        myViewHolder.m_name.setText(mrname);
        final String intro=marketBean.getIntro();
        final String address=items.get(position).getAddress();
        myViewHolder.m_address.setText(address);
        final String level=marketBean.getLevel();
        myViewHolder.m_star.setText(level+"星级");
        final String shop_id=items.get(position).getMrid();
        final String pic=items.get(position).getPic();
        final String phone=items.get(position).getPhone();

        Picasso.with(context).load(items.get(position).getPic()).into(myViewHolder.m_img);

        myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(context, FoodByShopActivity.class
                );
                intent1.putExtra("SHOPID",shop_id);
                intent1.putExtra("mrname",mrname);
                intent1.putExtra("Pic",pic);
                intent1.putExtra("phone",phone);
                intent1.putExtra("address",address);
                context.startActivity(intent1);
            }
        });
    }


}
